package com.yifi.common.plugins.influxDB;

import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.InfluxDBClientFactory;
import com.jfinal.plugin.IPlugin;

import java.util.List;

/**
 * @author 姚善利
 * @classname com.yifi.common.plugins.influxdb
 * @description
 * @date 2022/11/3 8:53
 */
public class InfluxDBPlugin implements IPlugin {

    protected InfluxDBClient client;

    protected String url;
    protected String token;
    protected String bucket;
    protected String org;

    public InfluxDBPlugin(String url,String token,String bucket,String org) {
        this.url=url;
        this.token=token;
        this.bucket=bucket;
        this.org=org;
    }

    @Override
    public boolean start() {
        if(client==null)
        {
            client= InfluxDBClientFactory.create(url,token.toCharArray());
        }
        InfluxDBUtils.init(client,bucket,org);
        return true;
    }

    @Override
    public boolean stop() {
        InfluxDBUtils.close();
        return true;
    }
}
